import 'dart:async';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:enterprise_v8/app/components/toast_widget.dart';
import 'package:enterprise_v8/router/app_pages.dart';

class VerifyControl extends GetxController {

  final TextEditingController phoneController = TextEditingController();
  final TextEditingController codeController = TextEditingController();
  RxBool isSendingCode = false.obs;
  RxInt secondsRemaining = 60.obs;

  // 发送验证码
  void startCountdown() {
    secondsRemaining.value = 60;
    Timer.periodic(const Duration(seconds: 1), (timer) {
      if (secondsRemaining > 0) {
        secondsRemaining--;
      } else {
        timer.cancel();
        isSendingCode.value = false;
      }
    });
  }

  // 验证按钮
  void verify() {
    if (phoneController.text.isEmpty) {
      AppToast.showWarning('请输入手机号');
      return;
    }
    if (codeController.text.isEmpty) {
      AppToast.showWarning('请输入验证码');
      return;
    }
    // 验证手机号和验证码
    if (true) {
      Get.offAllNamed(Routes.home);
      AppToast.showSuccess('验证成功');
    } else {
      AppToast.showWarning('验证失败');
    }
  }

}
